<html>
<head><meta charset="utf-8"><title>miri and cfg vs is_feature_detected · t-libs/stdarch · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/index.html">t-libs/stdarch</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html">miri and cfg vs is_feature_detected</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="177809199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177809199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177809199">(Oct 10 2019 at 13:25)</a>:</h4>
<p><a href="https://github.com/rust-lang/stdarch/pull/803#issuecomment-540565592" target="_blank" title="https://github.com/rust-lang/stdarch/pull/803#issuecomment-540565592">from here</a></p>



<a name="177809268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177809268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177809268">(Oct 10 2019 at 13:26)</a>:</h4>
<p>why you would do this?</p>



<a name="177809278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177809278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177809278">(Oct 10 2019 at 13:26)</a>:</h4>
<p>and why it would be an UB?</p>



<a name="177831915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177831915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177831915">(Oct 10 2019 at 17:16)</a>:</h4>
<p>it was just an example</p>



<a name="177831937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177831937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177831937">(Oct 10 2019 at 17:16)</a>:</h4>
<p>what i meant is that one can write code like that, that would invoke UB if it were executed</p>



<a name="177831981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177831981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177831981">(Oct 10 2019 at 17:17)</a>:</h4>
<p>but since <code>is_x86_feature_detected!</code> and <code>cfg(target_feature)</code> are "consistent" with each other,  such code will never be executed</p>



<a name="177831993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177831993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177831993">(Oct 10 2019 at 17:17)</a>:</h4>
<p>so as a consequence, right now, code like that never exhibits UB</p>



<a name="177832125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177832125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177832125">(Oct 10 2019 at 17:18)</a>:</h4>
<p>if we were to change <code>is_x86_..._detected</code> under miri to be inconsistent with <code>cfg(target_feature)</code>, then such UB could end up being executed</p>



<a name="177833269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/177833269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#177833269">(Oct 10 2019 at 17:31)</a>:</h4>
<p>this reminds me of the environment variable to override the macro results</p>



<a name="178080950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178080950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178080950">(Oct 14 2019 at 07:51)</a>:</h4>
<p>The assumption is that you can always disable a path even if you build such path</p>



<a name="178081035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081035">(Oct 14 2019 at 07:53)</a>:</h4>
<p>the env override is the equivalent of shutting off the simd flag at kernel level or just executing the binary on a different cpu</p>



<a name="178081063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081063">(Oct 14 2019 at 07:53)</a>:</h4>
<p>so if something would be a UB in that case there is a much worse problem than just miri being strange</p>



<a name="178081229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081229">(Oct 14 2019 at 07:56)</a>:</h4>
<p>You may short-circuit <code>is_..._detected!</code> to always return false if <code>cfg(target_feature)</code> is false, but it may and should return true or false if <code>cfg(target_feature)</code> is true.</p>



<a name="178081352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081352">(Oct 14 2019 at 07:58)</a>:</h4>
<p><span class="user-mention" data-user-id="131070">@Luca Barbato</span> if you compile a binary for a CPU that has some feature enable, the behavior is undefined if the CPU does not have the feature enabled</p>



<a name="178081385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081385">(Oct 14 2019 at 07:59)</a>:</h4>
<p>so what happens if I want to build a binary using a compiler that supports avx2 and then run it on a cpu that does not have avx2?</p>



<a name="178081390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081390">(Oct 14 2019 at 07:59)</a>:</h4>
<p>so if the following assert fails, your program has exhibited UB the moment you started executing it</p>
<div class="codehilite"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="n">cfg</span><span class="o">!</span><span class="p">(</span><span class="n">target_feature</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;X&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">assert</span><span class="o">!</span><span class="p">(</span><span class="n">is_x86_feature_detected</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;X&quot;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="178081407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081407">(Oct 14 2019 at 07:59)</a>:</h4>
<p><span class="user-mention" data-user-id="131070">@Luca Barbato</span> that's UB</p>



<a name="178081459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081459">(Oct 14 2019 at 08:00)</a>:</h4>
<p>we will optimize your whole program under the assumption that AVX2 is available</p>



<a name="178081467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081467">(Oct 14 2019 at 08:00)</a>:</h4>
<p>so we make no guarantees about what happens if you try to run such program on a CPU without AVX2</p>



<a name="178081477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081477">(Oct 14 2019 at 08:00)</a>:</h4>
<p>it is a problem</p>



<a name="178081479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081479">(Oct 14 2019 at 08:00)</a>:</h4>
<p>anything can happen</p>



<a name="178081496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081496">(Oct 14 2019 at 08:00)</a>:</h4>
<p>that makes the runtime checks for cpu features not exactly useful</p>



<a name="178081527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081527">(Oct 14 2019 at 08:01)</a>:</h4>
<p>you can compile your whole program without AVX2, and one function with AVX2</p>



<a name="178081537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081537">(Oct 14 2019 at 08:01)</a>:</h4>
<p>as long as you don't call that function on CPUs without AVX2, no UB happens</p>



<a name="178081557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081557">(Oct 14 2019 at 08:01)</a>:</h4>
<p>the run-time checks tell you whether calling that function is ok</p>



<a name="178081582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081582">(Oct 14 2019 at 08:01)</a>:</h4>
<p>but if you compiled your whole program for AVX2, then the run-time check returns always true</p>



<a name="178081642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081642">(Oct 14 2019 at 08:02)</a>:</h4>
<p>that's my expectation, I'm not sure I understand then "compile your whole program for"</p>



<a name="178081644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081644">(Oct 14 2019 at 08:02)</a>:</h4>
<p>because we don't allow such programs running on CPUs without AVX2</p>



<a name="178081656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081656">(Oct 14 2019 at 08:02)</a>:</h4>
<p><code>-C target-feature=+avx2</code></p>



<a name="178081695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081695">(Oct 14 2019 at 08:03)</a>:</h4>
<p>The only way <code>cfg!(target_feature = "avx2")</code> returns true is if AVX2 is enabled for all functions in a program</p>



<a name="178081715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081715">(Oct 14 2019 at 08:03)</a>:</h4>
<p>this needs some additional documentation</p>



<a name="178081718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081718">(Oct 14 2019 at 08:03)</a>:</h4>
<p>That's documented in the std::arch docs</p>



<a name="178081720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081720">(Oct 14 2019 at 08:03)</a>:</h4>
<p>and in the compiler docs</p>



<a name="178081727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081727">(Oct 14 2019 at 08:03)</a>:</h4>
<p>(the compiler user guide)</p>



<a name="178081775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081775">(Oct 14 2019 at 08:04)</a>:</h4>
<p><code>-C target-feature=+avx2</code> says the CPU this binary runs on has the AVX2 feature, so use it wherever you want</p>



<a name="178081788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081788">(Oct 14 2019 at 08:04)</a>:</h4>
<p><code>-C target-cpu=foo</code> says the CPU this binary runs on is <code>foo</code>, so use all features that <code>foo</code> has</p>



<a name="178081818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081818">(Oct 14 2019 at 08:05)</a>:</h4>
<p>The different target triples enable different base CPUs, features, etc.</p>



<a name="178081844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081844">(Oct 14 2019 at 08:05)</a>:</h4>
<p>This is not different than compiling a binary for <code>x86_64-unknown-linux-gnu</code>, and trying to run that binary on windows</p>



<a name="178081867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081867">(Oct 14 2019 at 08:05)</a>:</h4>
<p>we can't even guarantee that that fails</p>



<a name="178081924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081924">(Oct 14 2019 at 08:06)</a>:</h4>
<p>there are no checks or anything that we can reasonably insert to prevent the execution of such a program</p>



<a name="178081943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081943">(Oct 14 2019 at 08:06)</a>:</h4>
<p>those checks would be compiled for linux, and they would be meaningless on other systems</p>



<a name="178081945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081945">(Oct 14 2019 at 08:06)</a>:</h4>
<p>same for AVX2</p>



<a name="178081957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081957">(Oct 14 2019 at 08:06)</a>:</h4>
<p>My reading of <a href="https://doc.rust-lang.org/core/arch/index.html" target="_blank" title="https://doc.rust-lang.org/core/arch/index.html">this</a></p>



<a name="178081961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081961">(Oct 14 2019 at 08:06)</a>:</h4>
<p>the compiler will generate code for those checks under the assumption that AVX2 is available</p>



<a name="178081971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081971">(Oct 14 2019 at 08:07)</a>:</h4>
<p>would be that you need to turn the target_feature on to build the code</p>



<a name="178081990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178081990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178081990">(Oct 14 2019 at 08:07)</a>:</h4>
<blockquote>
<p>Statically enabling a feature is typically done with the -C target-feature or -C target-cpu flags to the compiler. <br>
Note that when you compile a binary with a particular feature enabled it's important to ensure that you only run the binary on systems which satisfy the required feature set.</p>
</blockquote>



<a name="178082078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082078">(Oct 14 2019 at 08:08)</a>:</h4>
<p>the question now is "how do I build something that has avx2 code while running also on non-avx2 machines?"</p>



<a name="178082084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082084">(Oct 14 2019 at 08:08)</a>:</h4>
<p><a href="https://github.com/rust-lang-nursery/reference/blob/master/src/behavior-considered-undefined.md" target="_blank" title="https://github.com/rust-lang-nursery/reference/blob/master/src/behavior-considered-undefined.md">https://github.com/rust-lang-nursery/reference/blob/master/src/behavior-considered-undefined.md</a></p>
<blockquote>
<p>Behavior considered undefined: [...]<br>
Executing code compiled with platform features that the current platform does not support (see target_feature).</p>
</blockquote>



<a name="178082136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082136">(Oct 14 2019 at 08:09)</a>:</h4>
<blockquote>
<p>the question now is "how do I build something that has avx2 code while running also on non-avx2 machines?"</p>
</blockquote>
<p>You compile for a target that doesn't have AVX2, use <code>#[target_feature]</code> to enable AVX2 on the functions in which you want to allow the compiler to use it, and guard calls to those functions with <code>is_x86_feature_detected!("avx2")</code></p>



<a name="178082137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082137">(Oct 14 2019 at 08:09)</a>:</h4>
<p><code>#[target_feature(enable = "avx2")]</code> vs `#[cfg(target_feature = "avx2")]</p>



<a name="178082195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082195">(Oct 14 2019 at 08:10)</a>:</h4>
<p>this should be stressed ^^</p>



<a name="178082213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082213">(Oct 14 2019 at 08:10)</a>:</h4>
<p><a href="https://doc.rust-lang.org/core/arch/index.html#dynamic-cpu-feature-detection" target="_blank" title="https://doc.rust-lang.org/core/arch/index.html#dynamic-cpu-feature-detection">https://doc.rust-lang.org/core/arch/index.html#dynamic-cpu-feature-detection</a></p>



<a name="178082234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082234">(Oct 14 2019 at 08:11)</a>:</h4>
<blockquote>
<p>Sometimes statically dispatching isn't quite what you want. Instead you might want to build a portable binary that runs across a variety of CPUs, but at runtime it selects the most optimized implementation available. This allows you to build a "least common denominator" binary which has certain sections more optimized for different CPUs.</p>
<p>Taking our previous example from before, we're going to compile our binary without AVX2 support, but we'd like to enable it for just one function.</p>
</blockquote>



<a name="178082343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082343">(Oct 14 2019 at 08:12)</a>:</h4>
<p>I guess that's enough and it is me not reading carefully</p>



<a name="178082500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178082500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178082500">(Oct 14 2019 at 08:15)</a>:</h4>
<p>having a <code>-C target_feature=miri</code> would be enough to avoid the UB?</p>



<a name="178083683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083683">(Oct 14 2019 at 08:34)</a>:</h4>
<p>Well not really - cc <span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="178083701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083701">(Oct 14 2019 at 08:34)</a>:</h4>
<p>The problem is that <code>miri</code> doesn't want to be a rust target</p>



<a name="178083720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083720">(Oct 14 2019 at 08:34)</a>:</h4>
<p>But instead emulate all targets supported by Rust</p>



<a name="178083738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083738">(Oct 14 2019 at 08:35)</a>:</h4>
<p>So if that's miris goal, the problem is that miri doesn't emulate run-time feature detection yet</p>



<a name="178083751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083751">(Oct 14 2019 at 08:35)</a>:</h4>
<p>nor the intrinsics</p>



<a name="178083821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083821">(Oct 14 2019 at 08:36)</a>:</h4>
<p>We could implement emulation of run-time feature detection for miri, e.g., by just returning the same value as <code>cfg!(target_feature)</code>, for example</p>



<a name="178083829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083829">(Oct 14 2019 at 08:36)</a>:</h4>
<p>and then we could implement all intrinsics that those features allow on miri</p>



<a name="178083872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083872">(Oct 14 2019 at 08:37)</a>:</h4>
<p>that's a titanic amount of work, but if <code>miri</code>s goal is to emulate the semantics of a target, then... that's what it has to do</p>



<a name="178083878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083878">(Oct 14 2019 at 08:37)</a>:</h4>
<p>at least, to be able to run code that uses these parts of the language</p>



<a name="178083979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178083979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178083979">(Oct 14 2019 at 08:39)</a>:</h4>
<p>I'm tending more that this would be the right thing to do according to miris goal's, this means that all code using intrinsics would just abort on the first intrinsic, and until miri supports them such code can just <code>cfg!(miri)</code> its way out of the situation</p>



<a name="178084094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084094">(Oct 14 2019 at 08:40)</a>:</h4>
<p><code>is_x86_feature_detected!</code> can use <code>cfg!(miri)</code> to just return the value of <code>cfg!(target_feature)</code>, but it cannot returne <code>false</code> for a query for which <code>cfg!(target_feature)</code> returns <code>true</code> because that would be an error in the abstract machine</p>



<a name="178084129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084129">(Oct 14 2019 at 08:41)</a>:</h4>
<p>if that happens, the behavior is undefined, according to the reference, so doing so would be purportedly implementing <code>is_x86_feature_detected</code> to have UB under miri</p>



<a name="178084317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084317">(Oct 14 2019 at 08:44)</a>:</h4>
<p>So I think that the logic that you implemented <span class="user-mention" data-user-id="131070">@Luca Barbato</span> is indeed the correct one</p>



<a name="178084521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084521">(Oct 14 2019 at 08:47)</a>:</h4>
<p>I wonder if -C target_feature=-${foo} is doing what it should</p>



<a name="178084554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084554">(Oct 14 2019 at 08:47)</a>:</h4>
<p>that _might_ solve the current problem and allows to flip on the cpu feature once it is supported</p>



<a name="178084565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084565">(Oct 14 2019 at 08:47)</a>:</h4>
<p>Maybe we could expand the cfg(miri) comment with the information, that a consequence of returning <code>true</code> for the features enabled at compile-time is that branches on, e.g., <code>is_x86_feature_detected!("sse")</code> will return <code>true</code> for  <code>miri</code> causing <code>miri</code> to try to execute SSE intrinsics, which will fail. Users that don't want this to happen should handle the <code>cfg!(miri)</code> case instead.</p>



<a name="178084614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084614">(Oct 14 2019 at 08:48)</a>:</h4>
<p><span class="user-mention" data-user-id="131070">@Luca Barbato</span> <code>-C target-feature=-sse</code> disables SSE for the crates compiled with that flag</p>



<a name="178084625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084625">(Oct 14 2019 at 08:48)</a>:</h4>
<p>and in those crates, <code>cfg!(target_feature = "sse")</code> will return false</p>



<a name="178084642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084642">(Oct 14 2019 at 08:48)</a>:</h4>
<p>and so will <code>is_x86_feature_detected!</code></p>



<a name="178084651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084651">(Oct 14 2019 at 08:48)</a>:</h4>
<p>so it would short circuit correctly</p>



<a name="178084663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084663">(Oct 14 2019 at 08:49)</a>:</h4>
<p>in general, libstd is not re-compiled with <code>-C target-features</code></p>



<a name="178084686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084686">(Oct 14 2019 at 08:49)</a>:</h4>
<p>so SSE will still be enabled for libstd, and that changes the Rust ABI of, e.g., which registers are used for passing floats</p>



<a name="178084688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084688">(Oct 14 2019 at 08:49)</a>:</h4>
<p>it would just need a tiny wrapper to turn off all the unsupported features</p>



<a name="178084711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084711">(Oct 14 2019 at 08:49)</a>:</h4>
<p>so that would trigger UB of the form "calling an function through an incompatible ABI declaration"</p>



<a name="178084774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084774">(Oct 14 2019 at 08:50)</a>:</h4>
<p>If <code>miri</code> re-compiles <code>libstd</code></p>



<a name="178084780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084780">(Oct 14 2019 at 08:50)</a>:</h4>
<p>Then that would not have UB on miri though</p>



<a name="178084798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084798">(Oct 14 2019 at 08:50)</a>:</h4>
<p>So <code>miri</code> could, on x86_64, always call rustc with <code>-C target-feature=-mmx</code></p>



<a name="178084808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084808">(Oct 14 2019 at 08:51)</a>:</h4>
<p>to avoid many of the stable intrinsics</p>



<a name="178084823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084823">(Oct 14 2019 at 08:51)</a>:</h4>
<p>as long as it recompiles libstd with it</p>



<a name="178084848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084848">(Oct 14 2019 at 08:51)</a>:</h4>
<p>Maybe we could add a <code>-C target-cpu=miri</code> that does this ? cc <span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="178084852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084852">(Oct 14 2019 at 08:51)</a>:</h4>
<p>sounds a path to consider to me</p>



<a name="178084945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084945">(Oct 14 2019 at 08:52)</a>:</h4>
<p>I don't know if <code>-C target-feature=-mmx</code> would be enough, maybe one needs <code>-C target-feature=-mmx,-sse,-sse2,...,-avx512f,avx512foobarbaz</code></p>



<a name="178084956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084956">(Oct 14 2019 at 08:53)</a>:</h4>
<p>yep, thus why I suggested a wrapper :)</p>



<a name="178084971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084971">(Oct 14 2019 at 08:53)</a>:</h4>
<p>or just the shorthand above</p>



<a name="178084984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084984">(Oct 14 2019 at 08:53)</a>:</h4>
<p>miri would probably want to detect whether the user tries to use <code>-C target-feature</code> or <code>-C target-cpu</code> in their RUSTFLAGS or cargo config and error or warn</p>



<a name="178084989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178084989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178084989">(Oct 14 2019 at 08:53)</a>:</h4>
<p><code>=miri</code> -&gt; <code>=-all</code></p>



<a name="178085006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178085006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178085006">(Oct 14 2019 at 08:53)</a>:</h4>
<p>yeah</p>



<a name="178085078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/miri%20and%20cfg%20vs%20is_feature_detected/near/178085078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/miri.20and.20cfg.20vs.20is_feature_detected.html#178085078">(Oct 14 2019 at 08:54)</a>:</h4>
<p>I'll open an issue on the miri repo</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>